﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;

namespace GasolineSite
{
    public class MD5Helper
    {
        private static MD5 _md5 ;

        static MD5Helper()
        {
            _md5 = MD5.Create();
        }

        public static string GetMD5Hash(string input)
        {
            byte[] data = _md5.ComputeHash(Encoding.UTF8.GetBytes(input));

            var sb = new StringBuilder();

            for (int i = 0; i < data.Length; i++ )
                sb.Append(data[i].ToString("X2"));

            return sb.ToString();
        }

        public static bool VerifyString(string input, string hash)
        {
            var inputHash = GetMD5Hash(input);

            var comparer = StringComparer.OrdinalIgnoreCase;

            return 0 == comparer.Compare(inputHash, hash);
        }
    }
}